package com.zheng.pvz.utils
{
	import flash.display.DisplayObject;
	import flash.geom.Point;

	/**
	 *编号转换坐标 
	 * 
	 */
	public class NumberToCoo
	{
		
		private static var instance:NumberToCoo;
		
		private const SPACEX:int=82;//间隔
		private const SPACEY:int=82;
		private const STARTX:int=50;//起点坐标
		private const STARTY:int=200;
		
		public function NumberToCoo(singleton:Singleton)
		{
			if(!singleton)return;
		}
		public static function getInstance():NumberToCoo{
			if(instance){
				return instance;
			}else{
				return instance=new NumberToCoo(new Singleton);
			}
			
		}
		/**
		 * 根据编号返回坐标
		 * @param p
		 * @return 
		 * 
		 */
		public function numToCoo(displayObject:DisplayObject,p:Point):Point{
			var cx:int=p.x*this.SPACEX+this.STARTX;
			var cy:int=p.y*this.SPACEY+this.STARTY;
			displayObject.x=cx;
			displayObject.y=cy
			return new Point(cx,cy);
		}
		/**
		 * 根据坐标返回编号 
		 * @param p 坐标
		 * @return 编号
		 * 
		 */
		public function cooToNum(p:Point):Point{
			var row:int=int((p.x-this.STARTX)/this.SPACEX);
			var cols:int=int((p.y-this.STARTY)/this.SPACEY);
			return new Point(row,cols);
		}
	}
}
class Singleton{}